Ext.ns('cn.hls.web.action.biz.shipper');
var shipperForm = cn.hls.web.action.biz.shipper.shipperForm;
 shipperForm = function() {
	var uploadPanel,win;
   return { 
      init : function() {
    	this.initRender();
      },
      /**企业基本信息下拉框 store**/
      createCompanyStore:function(){
     	 return new Ext.data.Store({
     		 	autoLoad:true,//自动加载   
 				proxy : new Ext.data.HttpProxy({ url : cfg.cxt+'/company/loadCompany.action?type=2' }),
 				reader : new Ext.data.JsonReader({idProperty : 'id'},
 				["id","name"]),
 				listeners : { 
 					loadexception : bangni.storeLoadError
 				}
 			});
      },
      ajaxFileUpload:function(){
    	  var filepath =$("#photoFile").val();
    		 var extStart = filepath.lastIndexOf(".");
    	     var ext = filepath.substring(extStart, filepath.length).toUpperCase();
    	     if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG"){
    	    	 Ext.Mytip.msg('提示','文件格式不正确,请允许上传后辍名为bmp、gif、png、jpg、jpeg的文件!');
    	    	 return;
    	     }else{
    	    	 var size=document.getElementById("photoFile").files[0].size;
    	    	 if(size>3*1024*1024){//最大不能超过3M
    	    		// alert("上传文件超过规定大小!");
    	    		 Ext.Mytip.msg('提示','上传文件超过规定3M大小!');
    	    		 return;
    	    	 }
    	     }
    	     $.ajaxFileUpload({  
    	         url: cfg.cxt+'/upload/uploadFile.action', 
    	         secureuri: false,  
    	         fileElementId: 'photoFile',  
    	         dataType: 'json', //这里修改为content  
    	         data:{"photo":$("#hid_photo").val()},
    	         success: function (data, status) {  
    	           if(status=="success"){
    	        	   //alert("文件传成功");
    	        	   Ext.Mytip.msg('提示','文件传成功!');
    	        	   $("#img_photo").attr('src',cfg.cxt+"/upload/"+data.info);
    	        	   $("#hid_photo").val(data.info);
    	           }else{
    	        	   Ext.Mytip.msg('提示','文件上传失败!');
    	           }
    	         },  
    	                   
    	         error: function (data, status, e) {  
    	            Ext.Mytip.msg('提示','文件上传失败，原因:'+e);
    	         }  
    	       }  
    	     )  
      },
      createUploadWin:function(){
    	  if(!uploadPanel){
    		  shipperForm.createUploadPanel();
    	  }
    	  if(!win){
    		  win = new ExtWin({
    			width : 300,
  				height : 150,
  				title : '<div class="panelTitleCss">联系人身份证正反面照片上传</div>',
    		  	items:[uploadPanel],
    		  	buttons : [{
					text : '保存',
					id:"btn_Save",
					iconCls : 'acceptIcon',
					handler : function() {
						shipperForm.ajaxFileUpload();
						$("#photo").hide();
						win.hide();
					}
    		  	},{
					text : '关闭',
					iconCls : 'deleteIcon',
					handler : function() {
						win.hide();
					}
				}]
    		  });
    	  }
    	  win.show();
      },
      createUploadPanel:function(){
    	  uploadPanel=new Ext.Panel({
    		  layout : 'fit',
    		  items: [{
		        	padding : 5,
					bodyStyle:'overflow-y:auto;overflow-x:hidden;',
					contentEl : 'photoFile'
		        }]
    	  });
    	  return uploadPanel;
      },
		
      initRender: function(){
     	new Ext.Button({
            text : '身份证上传',
            renderTo : 'idnoImg_div',
            handler : function() {
            	$("#photoFile").val('');
            	$("#photoFile").show();
            	shipperForm.createUploadWin();
            }
         });
          
          
    	  new Ext.form.ComboBox({ //默认过滤参数名为query     
              store: shipperForm.createCompanyStore(),    
              hiddenName:'company.name',
              id:'company',
              width : 550,
              mode : 'local', //设置为local,则加载的本地数据     
              typeAheadDelay:250,//默认延时查询250     
              triggerAction : 'all', //每次下拉均显示全部选项       
              selectOnFocus:true,
              forceSelection: true,// 用户必须点击选择不能随意输入  
              typeAhead: true,// 自动提示并补充列出相似的选项  
              valueField : 'id', //下拉框显示信息对应的值     
              displayField : 'name', //下拉框显示信息     
              loadingText : '正在加载信息',      
              selectOnFocus : true, //用户不能自己输入,只能选择列表中有的记录     
              minChars:2,  //设置填充几个字节就去查一次,默认为4个字节      
              autocomplete:true,
              renderTo : 'sp_company',
              height:300,
    	  listeners : {  
    		  'select':function(combo,record,index){
             	 $("#companyId").val(record.data.id);
              },
    	        'beforequery' : function(e) {  
    	            var combo = e.combo;     
    	            if(!e.forceAll){     
    	            	   var input = e.query;    
    	                    // 检索的正则  
    	                   var regExp = new RegExp(".*" + input + ".*");  
    	                combo.store.filterBy(function(record,id){     
    	                	var text = record.get(combo.displayField);    
                            return regExp.test(text);    
    	                });  
    	                combo.expand();     
    	                return false;     
    	            }  
    	        }  
    	    }  
    	  });
	      $("#company").attr('datatype',"*");
	      //编辑时设置下拉框的默认值
	      if($("#companyId").val()!=''){
	    	  var name=$("#copmanyName").val();
	    	  $("#company").val(name);//下拉框设置值
	      }
      }
   }
}();
Ext.onReady(shipperForm.init, shipperForm);
 